import random
def hexstr( bs : bytes) -> str | None:
    return ''.join(
          '\\x' + format(b,'02x')
          for b in bs
    )

def hexdump(bs : bytes , prefix : str = '' ,start : int = 0) -> str | None:
    
    base  = start & (~15)
    start = start % 16
    
    return ''.join(
          ('\n' + prefix + ( format( (base + i) & (~15) ,'08x') + ' ') if i % 16 == 0 else '') +
          ('.. ' if i < start else (format(bs[i - start],'02x') + ' '))
          for i in range(0,len( bs ) + start)
    )
def gen_split_points(n : int) -> list[int] :
    split_points = [0]
    current = 0
    while current < n:
        max_step = n - current
        step = random.randint(1, max_step)
        current += step
        if current < n:
            split_points.append(current)
    split_points.append(n)
    return split_points

def gen_rand_spans(nums:int , n:int ) -> list[(int,int)] :
    spans = []
    for _ in range(nums):
        if n == 0:
            break
        substart = random.randint(0, n-1)
        subend = random.randint(substart + 1, n)
        spans.append((subend,substart))
    return spans
